package com.haiyi.software.app.basic;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;

import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

import com.haiyi.software.app.MainApplication;
import com.haiyi.software.xmpp.event.XMPPEvent;

public abstract class ActivityEx extends LoginActivityBasic implements
		XMPPEvent {

	public MainApplication app;

	public abstract void XmppReceiveMessage(Message msg);

	private Message saveMsg;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO 自动生成的方法存根
		super.onCreate(savedInstanceState);
		app = MainApplication.getInstance();
		app.addXMPPEvent(this);
	}

	@Override
	protected void onDestroy() {
		// TODO 自动生成的方法存根
		super.onDestroy();
		app.removeXMPPEvent(this);
		app = null;
		System.gc();
	}

	Handler UIMessage = new Handler() {
		@Override
		public void handleMessage(android.os.Message msg) {
			// TODO 自动生成的方法存根
			super.handleMessage(msg);
			Log.i("msg", msg.toString());
			XmppReceiveMessage(saveMsg);
		}
	};

	@Override
	public synchronized void XMPPConnectEvent(XMPPConnection connection) {
		// TODO 自动生成的方法存根

	}

	@Override
	public synchronized void XMPPAuthenticate(XMPPConnection connection) {
		// TODO 自动生成的方法存根

	}

	@Override
	public synchronized void XMPPNotAuthenticate(XMPPConnection connection) {
		// TODO 自动生成的方法存根

	}

	@Override
	public synchronized void XMPPReceiveMessage(Message msg) {
		// TODO 自动生成的方法存根
		saveMsg = msg;
		UIMessage.sendEmptyMessage(1);
	}

}
